home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / drawal1r / form1.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-08-15  |  7.6 KB  |  266 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    AutoRedraw      =   -1  'True
  4.    BackColor       =   &H00FFFFFF&
  5.    Caption         =   "Form1"
  6.    ClientHeight    =   6945
  7.    ClientLeft      =   0
  8.    ClientTop       =   315
  9.    ClientWidth     =   9660
  10.    ClipControls    =   0   'False
  11.    ControlBox      =   0   'False
  12.    Height          =   7380
  13.    Left            =   -60
  14.    LinkTopic       =   "Form1"
  15.    MaxButton       =   0   'False
  16.    MinButton       =   0   'False
  17.    ScaleHeight     =   7500
  18.    ScaleMode       =   0  'User
  19.    ScaleWidth      =   9660
  20.    Top             =   -60
  21.    Width           =   9780
  22.    Begin VB.PictureBox picEdit 
  23.       AutoRedraw      =   -1  'True
  24.       BackColor       =   &H00FFFFFF&
  25.       Height          =   7593
  26.       Left            =   0
  27.       ScaleHeight     =   8200
  28.       ScaleMode       =   0  'User
  29.       ScaleWidth      =   9645
  30.       TabIndex        =   0
  31.       Top             =   -45
  32.       Width           =   9705
  33.       Begin VB.PictureBox picHid 
  34.          AutoRedraw      =   -1  'True
  35.          BackColor       =   &H00FFFFFF&
  36.          BorderStyle     =   0  'None
  37.          Height          =   7530
  38.          Left            =   150
  39.          ScaleHeight     =   8200
  40.          ScaleMode       =   0  'User
  41.          ScaleWidth      =   1125
  42.          TabIndex        =   1
  43.          Top             =   510
  44.          Visible         =   0   'False
  45.          Width           =   1125
  46.       End
  47.    End
  48.    Begin MSComDlg.CommonDialog CommonDialog1 
  49.       Left            =   4230
  50.       Top             =   3225
  51.       _ExtentX        =   847
  52.       _ExtentY        =   847
  53.       _Version        =   327681
  54.       DialogTitle     =   "Load Picture"
  55.       Filter          =   "Pictures *.bmp |*.bmp"
  56.       InitDir         =   "C:\"
  57.    End
  58.    Begin VB.Menu mnuMain 
  59.       Caption         =   "Main"
  60.       Visible         =   0   'False
  61.       Begin VB.Menu mnuLoad 
  62.          Caption         =   "Load"
  63.       End
  64.       Begin VB.Menu mnuClear 
  65.          Caption         =   "Clear"
  66.       End
  67.       Begin VB.Menu mnuTrim 
  68.          Caption         =   "Trim"
  69.       End
  70.       Begin VB.Menu mnuCopy 
  71.          Caption         =   "Copy"
  72.       End
  73.       Begin VB.Menu mnuPaste 
  74.          Caption         =   "Paste"
  75.       End
  76.       Begin VB.Menu mnuSize 
  77.          Caption         =   "Size"
  78.          Begin VB.Menu mnu1p1X 
  79.             Caption         =   "1.1X"
  80.          End
  81.          Begin VB.Menu mnu1p2X 
  82.             Caption         =   "1.2X"
  83.          End
  84.          Begin VB.Menu mnu1p3X 
  85.             Caption         =   "1.3X"
  86.          End
  87.          Begin VB.Menu mnu1p5X 
  88.             Caption         =   "1.5X"
  89.          End
  90.          Begin VB.Menu mnu2X 
  91.             Caption         =   "2X"
  92.          End
  93.          Begin VB.Menu mnu3X 
  94.             Caption         =   "3X"
  95.          End
  96.          Begin VB.Menu mnu4X 
  97.             Caption         =   "4X"
  98.          End
  99.       End
  100.       Begin VB.Menu mnuReload 
  101.          Caption         =   "Reload"
  102.       End
  103.       Begin VB.Menu mnuSave 
  104.          Caption         =   "Save"
  105.       End
  106.       Begin VB.Menu mnuExit 
  107.          Caption         =   "Exit"
  108.       End
  109.    End
  110. Attribute VB_Name = "Form1"
  111. Attribute VB_Creatable = False
  112. Attribute VB_Exposed = False
  113. Option Explicit
  114. Private x1 As Single
  115. Private y1 As Single
  116. Private x2 As Single
  117. Private y2 As Single
  118. Private Drag As Boolean
  119. Private Sub Resize(Size As Single)
  120. Dim w As Single
  121. Dim h As Single
  122. w = picHid.ScaleWidth * Size
  123. h = picHid.ScaleHeight * Size
  124. picEdit.Cls
  125. On Error Resume Next
  126. picEdit.PaintPicture picHid.Picture, 0, 0, w, h, 0, 0, picHid.ScaleWidth, picHid.ScaleHeight
  127. picEdit.Picture = picEdit.Image
  128. End Sub
  129. Private Sub Swap()
  130. Dim var As Single
  131. If x1 > x2 Then
  132. var = x1
  133. x1 = x2
  134. x2 = var
  135. End If
  136. If y1 > y2 Then
  137. var = y1
  138. y1 = y2
  139. y2 = var
  140. End If
  141. End Sub
  142. Private Sub mnu1p1X_Click()
  143. Resize 1.1
  144. End Sub
  145. Private Sub mnu1p2X_Click()
  146. Resize 1.2
  147. End Sub
  148. Private Sub mnu1p3X_Click()
  149. Resize 1.3
  150. End Sub
  151. Private Sub mnu1p5X_Click()
  152. Resize 1.5
  153. End Sub
  154. Private Sub mnu2X_Click()
  155. Resize 2
  156. End Sub
  157. Private Sub mnu3X_Click()
  158. Resize 3
  159. End Sub
  160. Private Sub mnu4X_Click()
  161. Resize 4
  162. End Sub
  163. Private Sub mnuExit_Click()
  164. Unload Me
  165. End Sub
  166. Private Sub mnuReload_Click()
  167. Dim lRtn As Long
  168. lRtn = LoadImage(App.hInstance, CommonDialog1.filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE Or LR_LOADMAP3DCOLORS)
  169. Set picEdit.Picture = MoveBitmap(lRtn)
  170. End Sub
  171. Private Sub mnuLoad_Click()
  172. CommonDialog1.Action = 1
  173. Dim lRtn As Long
  174. lRtn = LoadImage(App.hInstance, CommonDialog1.filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE Or LR_LOADMAP3DCOLORS)
  175. Set picEdit.Picture = MoveBitmap(lRtn)
  176. End Sub
  177. Private Sub mnuSave_Click()
  178. If Not Clipboard.GetFormat(vbCFBitmap) Then Exit Sub
  179. Dim dat As OPENFILENAME
  180. dat.lStructSize = Len(dat)
  181. dat.hwndOwner = Form1.hwnd
  182. dat.hInstance = App.hInstance
  183. dat.lpstrFilter = "Pictures (*.bmp)" + Chr$(0) + "*.bmp"
  184. dat.nMaxFileTitle = 255
  185. dat.lpstrInitialDir = "C:\"
  186. dat.lpstrTitle = "Save Picture"
  187. dat.lpstrFile = Space$(254)
  188. dat.nMaxFile = 255
  189. dat.lpstrFileTitle = Space$(254)
  190. dat.flags = 0
  191. dat.lpstrFile = "C:\ClipPic.bmp"
  192. Dim a As Long
  193. a = GetSaveFileName(dat)
  194. If (a) Then
  195. SavePicture Clipboard.GetData(vbCFBitmap), Trim$(dat.lpstrFile)
  196. End If
  197. End Sub
  198. Private Sub mnuTrim_Click()
  199. Swap 'If necessary
  200. picHid.Width = x2 - x1 + 1
  201. picHid.Height = y2 - y1 + 1
  202. On Error Resume Next
  203. picHid.PaintPicture picEdit.Picture, 0, 0, x2 - x1 + 1, y2 - y1, x1, y1, x2 - x1 + 1, y2 - y1 + 1
  204. Clipboard.Clear
  205. Clipboard.SetData picHid.Image, vbCFBitmap
  206. picEdit.Picture = LoadPicture(vbNullString)
  207. If Not Clipboard.GetFormat(vbCFBitmap) Then Exit Sub
  208. picHid.Picture = Clipboard.GetData(vbCFBitmap)
  209. picEdit.PaintPicture picHid.Picture, x1, y1, picHid.ScaleWidth, picHid.ScaleHeight, 0, 0, picHid.ScaleWidth, picHid.ScaleHeight
  210. picEdit.Picture = picEdit.Image
  211. End Sub
  212. Private Sub mnuPaste_Click()
  213. If Not Clipboard.GetFormat(vbCFBitmap) Then Exit Sub
  214. picHid.AutoSize = True
  215. picHid.Picture = Clipboard.GetData(vbCFBitmap)
  216. picHid.AutoSize = False
  217. picEdit.PaintPicture picHid.Picture, x1, y1, picHid.ScaleWidth, picHid.ScaleHeight, 0, 0, picHid.ScaleWidth, picHid.ScaleHeight
  218. picEdit.Picture = picEdit.Image
  219. End Sub
  220. Private Sub mnuClear_Click()
  221. picEdit.Picture = LoadPicture(vbNullString)
  222. End Sub
  223. Private Sub mnuCopy_Click()
  224. Swap ' If necessary
  225. picHid.Width = x2 - x1 + 1
  226. picHid.Height = y2 - y1 + 1
  227. On Error Resume Next
  228. picHid.PaintPicture picEdit.Picture, 0, 0, x2 - x1 + 1, y2 - y1 + 1, x1, y1, x2 - x1 + 1, y2 - y1 + 1
  229. picHid.Picture = picHid.Image 'To be sure it redraws
  230. Clipboard.Clear
  231. Clipboard.SetData picHid.Image, vbCFBitmap
  232. End Sub
  233. Private Sub mnuMain_Click()
  234. mnuPaste.Enabled = Clipboard.GetFormat(vbCFBitmap)
  235. End Sub
  236. Private Sub picEdit_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  237. If Not Drag Then Exit Sub
  238. picEdit.Line (x1, y1)-(x2, y2), , B
  239. x2 = X
  240. y2 = Y
  241. picEdit.Line (x1, y1)-(x2, y2), , B
  242. End Sub
  243. Private Sub picEdit_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  244. If Button <> vbLeftButton Then Exit Sub
  245. Drag = True
  246. picEdit.DrawMode = vbInvert
  247. x1 = X
  248. y1 = Y
  249. x2 = X
  250. y2 = Y
  251. picEdit.Cls
  252. picEdit.Line (X, Y)-(X, Y), , B
  253. End Sub
  254. Private Sub picEdit_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  255. If Button = vbRightButton Then
  256. PopupMenu mnuMain
  257. Exit Sub
  258. End If
  259. If Not Drag Then Exit Sub
  260. Drag = False
  261. picEdit.DrawMode = vbCopyPen
  262. End Sub
  263. Private Sub Form_Load()
  264. Title Me, False
  265. End Sub
  266.